//
//  DingDingUtils.swift
//  DingDIngAuto
//
//  Created by liguandong on 2024/3/11.
//

import Foundation
import UIKit

//func openDingTalkUrl(_ targetUrl: String) -> Bool {
//    if targetUrl.isEmpty {
//        return false
//    }
//
//    let url = "dingtalk://dingtalkclient/page/link?url=\(targetUrl.dt_urlEncode())"
//    return UIApplication.shared.openURL(URL(string: url)!)
//}

//func openDingTalkUrl(_ targetUrl: String) -> Bool {
//    if targetUrl.isEmpty {
//        return false
//    }
//
//    guard let encodedUrlString = targetUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {
//        return false
//    }
//
//    let url = "dingtalk://dingtalkclient/page/link?url=\(encodedUrlString)"
//    return UIApplication.shared.openURL(URL(string: url)!)
//}


func openDingTalkUrl(_ targetUrl: String = "dingtalk://dingtalkclient/page/yunpan") -> Bool {
    if targetUrl.isEmpty {
        return false
    }
    
    guard let encodedUrlString = targetUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
          let url = URL(string: encodedUrlString) else {
        return false
    }
    
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
    return true
}
